package com.google.code.greenwood.confluencemavenreleaseinfomacro.xwork.actions;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.atlassian.cache.Cache;
import com.atlassian.cache.CacheManager;
import com.atlassian.confluence.core.ConfluenceActionSupport;
import com.atlassian.confluence.pages.AbstractPage;
import com.atlassian.confluence.pages.actions.PageAware;
import com.google.code.greenwood.confluencemavenreleaseinfomacro.macro.ReleaseInfoMacro;
import com.opensymphony.xwork.Action;

public class CacheRefreshAction extends ConfluenceActionSupport implements PageAware {
	
	/* Logging */
	private static final Logger log = LoggerFactory.getLogger(ReleaseInfoMacro.class);
	
	private static final long serialVersionUID = 8453122663507503589L;

	private String cachekey;
	
    private AbstractPage currentPage;
    
    private CacheManager cacheManager;
    

    @Override
    public String execute() throws Exception
    {
		Cache cache = cacheManager.getCache(ReleaseInfoMacro.RELEASEINFO_MACRO_CACHE_KEY);
		cache.remove(cachekey);
		log.info("remove cache key from macrocache: "+cachekey);

        return Action.SUCCESS;
    }

    @Override
    public AbstractPage getPage()
    {
        return currentPage;
    }

    @Override
    public void setPage(AbstractPage abstractPage)
    {
        currentPage = abstractPage;
    }

    @Override
    public boolean isPageRequired()
    {
        return true;
    }

    @Override
    public boolean isLatestVersionRequired()
    {
        return true;
    }

    @Override
    public boolean isViewPermissionRequired()
    {
        return true;
    }

	public void setCachekey(String cachekey) {
		this.cachekey = cachekey;
	}

	public void setCacheManager(CacheManager cacheManager) {
		this.cacheManager = cacheManager;
	}	
    
    

}
